import {reqGoodsListInfo} from '@/api'
const state = {
  goodsListInfo:{}
}
const mutations = {
  RECEIVE_GOODSLISTINFO(state,goodsListInfo){
    state.goodsListInfo = goodsListInfo
  }
}
const actions = {
  // action函数接收用户传递的参数，只能是一个
  // 如果用户需要传递多个参数，必须传递一个对象
  async getGoodsListInfo({commit},searchParams){
    const result = await reqGoodsListInfo(searchParams)
    if(result.code === 200){
      commit('RECEIVE_GOODSLISTINFO',result.data)
    }
  }
}




// 简化数据操作



const getters = {
  attrsList(state){
    // 为啥要或空数组，因为我们要保证vue当中获取到的不是undefined,如果是undefined，很有可能报错
    return state.goodsListInfo.attrsList || []
  },

  goodsList(state){
    return state.goodsListInfo.goodsList || []
  },

  trademarkList(state){
    return state.goodsListInfo.trademarkList || []
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}